/*
 * @lc app=leetcode.cn id=461 lang=javascript
 *
 * [461] 汉明距离
 */

// @lc code=start
/**
 * @param {number} x
 * @param {number} y
 * @return {number}
 */
var hammingDistance = function(x, y) {
    let binaryX = x.toString(2)
    let binaryY = y.toString(2)
    if (binaryX.length < binaryY.length) {
        // 确保 binaryX 长于 binaryY
        let temp = binaryX
        binaryX = binaryY
        binaryY = temp
    }
    let result = 0
    for (let index = 1; index < binaryX.length + 1; index++) {
        const X = binaryX[binaryX.length - index];
        const Y = binaryY[binaryY.length - index] || '0'
        if (X !== Y) {
            result++
        }
    }
    return result
};
// @lc code=end

